﻿# Timer.py: the timer module
# 02/06/09 - 2013
# Copyright(c) 2009 Victor Freire e Cássio Espindola. All rights reserved.
# Python 2.6.2

import pygame


'''
Usage example:

timerobj = Timer.Timer();

( . . . )


Frame start
timerobj.update()
mult_factor = timerobj.get_mult_factor()

( . . . )

sprite_position_x += sprite_speed * mult_factor

( . . . )

Frame end

'''

class Timer:
    def __init__(self):
        self.last_update = pygame.time.get_ticks()
        self.clock = pygame.time.Clock()
        self.time_variation = 0
        
    def get_mult_factor(self):
        ''' Returns the factor used to multiply the speed and find the position increment.'''
        return self.time_variation/1000.0 # multiply_factor
        
    def update(self):
        ''' Updates the timer. Call at the beginning of every frame. '''
        self.time_variation = self.clock.tick()




        

